﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace SGS.Cards.Equipment
{
    public abstract class EquipmentBase : Card
    {
        public EquipmentBase( Suit suit, int point, CardType type )
            : base( suit, point, type )
        {
        }

        public override string Name
        {
            get 
            { 
                return string.Format( "{0}-{1}", base.Name, EquipmentName ); 
            }
        }

        public virtual string EquipmentName
        {
            get
            {
                return NameMapping.ParseEquipment( this.CardType, this.GetType().Name );
            }
        }

        public static EquipmentBase Create( CardType type, string name, Suit suit, int point )
        {
            string fullname = null;
            switch (type)
            {
                case CardType.Weapon:
                    fullname = string.Format( "SGS.Cards.Equipment.Weapon.{0}", name );
                    return CreateCard( fullname, suit, point );
                case CardType.Armor:
                    fullname = string.Format( "SGS.Cards.Equipment.Armor.{0}", name );
                    return CreateCard( fullname, suit, point );
                case CardType.AttackHorse:
                    return new AttachHorseCard( suit, point, name );
                case CardType.DefenseHorse:
                    return new DefenseHorseCard( suit, point, name );
                default:
                    return null;
            }
        }

        private static EquipmentBase CreateCard( string typename, Suit suit, int point )
        {
            Type t = Assembly.GetExecutingAssembly().GetType( typename );
            if (t == null)
            {
                return null;
            }
            else
            {
                return (EquipmentBase)Activator.CreateInstance( t, new object[] { suit, point } );
            }
        }
    }
}
